/*
	Filename	:	dibsection.h
	Author(s)	:	Ray E. Bornert II
				:	Gregory R. Hnat
	Date		:	2001-JUN-18
	Copyright	:	(c) 2001 RealTimeGaming

	History		:
*/

//////////
// GATE //
//////////
#ifndef _DIBSECTION_H_
#define _DIBSECTION_H_

/////////////
// FORWARD //
/////////////
class DibSection;

//////////////
// INCLUDES //
//////////////
#include <windows.h>
#include <stdio.h>

/////////////
// DEFINES //
/////////////
#define USEJPEG		1
#define USEPNG		1

//ONLY ONE OF THESE SHOULD BE TRUE
//THEY ARE MUTUALLY EXCLUSIVE
#define USE32BITDIB (1)
#define USE24BITDIB	(0)

////////////
// OBJECT //
////////////
class DibSection
{

/////////////
// MEMBERS //
/////////////

private://MEMBERS



public:	//MEMBERS

	HBITMAP		m_hbmp;
	DIBSECTION	m_ds;

/////////////
// METHODS //
/////////////

private://METHODS

	void Init(void);
	void Clear(void);

public:	//METHODS

	DibSection ();
	~DibSection ();
	int Resize (USHORT depth, long width, long height);
	int Load (LPCSTR pfilename);
	int Load (FILE* pfp);
	int LoadBMP( LPCSTR pfilename );
	int Paint (HDC hdc, long x, long y);
	int PaintRect (HDC hdc, int x, int y, RECT* pr);

	long Width (void);
	long Height (void);
	long ByteWidth (void);
	short BitCount (void);
	BYTE* GetBits (long y=0, long x=0);
	BYTE* GetBitsAddress(void);
	HBITMAP GetBitmap (void);
	int GetTransparentColor( COLORREF *pColor );

	static int TransparentBlt
	(
//		HDC hdcDest,        // handle to destination DC
		DibSection *pDsDest,
		int nXOriginDest,   // x-coord of destination upper-left corner
		int nYOriginDest,   // y-coord of destination upper-left corner
		int nWidthDest,     // width of destination rectangle
		int hHeightDest,    // height of destination rectangle
//		HDC hdcSrc,         // handle to source DC
		DibSection *pDsSrc,
		int nXOriginSrc,    // x-coord of source upper-left corner
		int nYOriginSrc,    // y-coord of source upper-left corner
		int nWidthSrc,      // width of source rectangle
		int nHeightSrc,     // height of source rectangle
		UINT crTransparent  // color to make transparent
	);

	static int TransparentAlphaBlt
	(
//		HDC hdcDest,        // handle to destination DC
		DibSection *pDsDest,
		int nXOriginDest,   // x-coord of destination upper-left corner
		int nYOriginDest,   // y-coord of destination upper-left corner
		int nWidthDest,     // width of destination rectangle
		int hHeightDest,    // height of destination rectangle
//		HDC hdcSrc,         // handle to source DC
		DibSection *pDsSrc,
		int nXOriginSrc,    // x-coord of source upper-left corner
		int nYOriginSrc,    // y-coord of source upper-left corner
		int nWidthSrc,      // width of source rectangle
		int nHeightSrc,     // height of source rectangle
		UINT crTransparent  // color to make transparent
	);

	static int AlphaBlt
	(
		DibSection *pDsDest,
		int nXOriginDest,   // x-coord of destination upper-left corner
		int nYOriginDest,   // y-coord of destination upper-left corner
		int nWidthDest,     // width of destination rectangle
		int nHeightDest,    // height of destination rectangle
		DibSection *pDsSrc,
		int nXOriginSrc,    // x-coord of source upper-left corner
		int nYOriginSrc,    // y-coord of source upper-left corner
		int nWidthSrc,      // width of source rectangle
		int nHeightSrc      // height of source rectangle
	);

	static int AlphaTransBlt
	(
		DibSection *pDsDest,
		int nXOriginDest,   // x-coord of destination upper-left corner
		int nYOriginDest,   // y-coord of destination upper-left corner
		int nWidthDest,     // width of destination rectangle
		int nHeightDest,    // height of destination rectangle
		DibSection *pDsSrc,
		int nXOriginSrc,    // x-coord of source upper-left corner
		int nYOriginSrc,    // y-coord of source upper-left corner
		int nWidthSrc,      // width of source rectangle
		int nHeightSrc,     // height of source rectangle
		int trans=0
	);

	static int Clip
	(
		RECT *pSrc,
		RECT *pSrcSub,
		RECT *pDst,
		RECT *pDstSub
	);

	static int Clip2
	(
		DibSection *pDsDest,
		int& nXOriginDest,   // x-coord of destination upper-left corner
		int& nYOriginDest,   // y-coord of destination upper-left corner
		int& nWidthDest,     // width of destination rectangle
		int& nHeightDest,    // height of destination rectangle
		DibSection *pDsSrc,
		int& nXOriginSrc,    // x-coord of source upper-left corner
		int& nYOriginSrc,    // y-coord of source upper-left corner
		int& nWidthSrc,      // width of source rectangle
		int& nHeightSrc     // height of source rectangle
	);

	int LoLiteRect( RECT *pRect, int level );
	int HiLiteRect( RECT *pRect, int level );
	int AlphaRect( RECT *pRect, double level );
	int AlphaFill( RECT *pRect, COLORREF color );
	int Compliment( RECT *pRect );
	int AlphaFrame( RECT *pDest, RECT *pSrc, COLORREF color );
	int SolidFillRect( RECT *pRect, COLORREF color );
	static long ReverseOrder( long COLOR );
	int IsVisiblePixel( int x, int y );
	int DrawGrid();


#ifdef _DEBUG
	static int Test (HWND hwnd);
#endif
};

#ifdef __cplusplus
extern "C"
{
#endif

	int DibSectionBlit
	(
		DibSection* pdest,
		DibSection* psrc,
		int destx,
		int desty,
		RECT* prsrc
	);

	void DibSectionFill24
	(
		DibSection* pimg,
		COLORREF cr
	);

	int DibSectionTBlit
	(
		DibSection* pdest,
		DibSection* psrc,
		long destx,
		long desty,
		RECT* prsrc,
		COLORREF c
	);

#ifdef __cplusplus
}
#endif


#endif